/* Global Styles and Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Comic Sans MS', 'Chalkboard SE', 'Arial Rounded MT Bold', sans-serif;
    overflow: hidden;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

/* Main container - adapts to iframe or standalone */
#app-container {
    width: 100%;
    height: 450px; /* Default for iframe */
    position: relative;
    overflow: hidden;
    background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
}

/* Standalone mode detection - uses 90vh when not in iframe */
@media (min-height: 500px) {
    body:not(.in-iframe) #app-container {
        height: 90vh;
    }
}

/* Screen Management */
.screen {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    display: none;
    flex-direction: column;
    padding: 10px;
    gap: 8px;
}

.screen.active {
    display: flex;
}

/* Tooltip - appears on hover to save vertical space */
.tooltip {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 14px;
    z-index: 1000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    max-width: 80%;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.tooltip.show {
    opacity: 1;
}

/* Story Panel - cute design with character */
.story-panel {
    background: white;
    border-radius: 16px;
    padding: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    position: relative;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border: 3px solid #ff9a9e;
}

.character-avatar {
    position: absolute;
    top: -20px;
    left: 15px;
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.avatar-emoji {
    font-size: 28px;
}

.story-text {
    font-size: 15px;
    line-height: 1.4;
    color: #333;
    margin-top: 30px;
    text-align: left;
}

/* Timer Bar - creates time pressure */
.timer-bar {
    position: relative;
    height: 24px;
    background: #e0e0e0;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.timer-fill {
    height: 100%;
    background: linear-gradient(90deg, #4facfe 0%, #00f2fe 100%);
    transition: width 0.1s linear;
    border-radius: 12px;
}

.timer-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-weight: bold;
    color: #333;
    font-size: 13px;
}

/* Matching Area - for matching mechanics */
.matching-area {
    display: none; /* Hidden by default, shown during matching challenges */
    flex: 1;
    gap: 10px;
    padding: 0;
}

.matching-area.active {
    display: flex;
}

.match-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.match-item {
    background: white;
    padding: 12px;
    border-radius: 12px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 3px solid transparent;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    font-size: 13px;
    user-select: none;
    min-height: 44px; /* Touch-friendly size */
    display: flex;
    align-items: center;
    justify-content: center;
}

.match-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.match-item.selected {
    border-color: #4facfe;
    background: #e3f2fd;
    transform: scale(1.05);
}

.match-item.correct {
    border-color: #4caf50;
    background: #c8e6c9;
    animation: correctPulse 0.5s ease;
}

.match-item.incorrect {
    border-color: #f44336;
    background: #ffcdd2;
    animation: shake 0.5s ease;
}

.match-item.matched {
    opacity: 0.5;
    pointer-events: none;
    background: #e8f5e9;
}

/* Choices Area - for narrative choices */
.choices-area {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.choice-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    min-height: 44px; /* Touch-friendly */
    text-align: center;
    font-family: inherit;
}

.choice-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}

.choice-btn:active {
    transform: translateY(0);
}

/* Progress Bar */
.progress-bar {
    height: 8px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #f093fb 0%, #f5576c 100%);
    width: 0%;
    transition: width 0.5s ease;
    border-radius: 4px;
}

/* Score Display */
.score-display {
    position: absolute;
    top: 15px;
    right: 15px;
    background: white;
    padding: 8px 16px;
    border-radius: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    font-weight: bold;
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 6px;
    z-index: 100;
}

#score-icon {
    font-size: 20px;
}

/* Result Screen */
.result-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 15px;
    background: white;
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.result-emoji {
    font-size: 80px;
    animation: bounceIn 0.8s ease;
}

.result-title {
    font-size: 28px;
    font-weight: bold;
    color: #667eea;
}

.result-message {
    font-size: 16px;
    color: #666;
    text-align: center;
    line-height: 1.5;
}

.final-score {
    font-size: 24px;
    font-weight: bold;
    color: #f5576c;
}

/* Audio Toggle Button */
.audio-toggle {
    position: absolute;
    top: 15px;
    left: 15px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: white;
    border: none;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    z-index: 100;
    transition: all 0.3s ease;
}

.audio-toggle:hover {
    transform: scale(1.1);
}

.audio-toggle.muted {
    opacity: 0.5;
}

/* Animations */
@keyframes correctPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

@keyframes bounceIn {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

/* Responsive adjustments for smaller screens */
@media (max-height: 450px) {
    .story-panel {
        min-height: 80px;
        padding: 10px;
    }
    
    .story-text {
        font-size: 13px;
        margin-top: 25px;
    }
    
    .choice-btn {
        padding: 10px 14px;
        font-size: 13px;
    }
    
    .match-item {
        padding: 10px;
        font-size: 12px;
    }
}